package com.example.demo.Dao;

import com.example.demo.bean.Records;
import com.example.demo.service.RecordsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RecordsDaoImpl implements RecordsDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void add(Records goods) {
        jdbcTemplate.update("insert into records(orderid,id,score,idclass,age,gender) values(?, ?, ?, ?, ?, ?)",
                goods.getOrderid(),goods.getId(),goods.getScore(),goods.getIdclass(),goods.getAge(),goods.getGender());
    }

    @Override
    public List<Records> findGoodsList(){
        List<Records> list=jdbcTemplate.query("select * from records",new Object[]{},new BeanPropertyRowMapper(Records.class));
        if(list!=null && list.size()>0){
            return  list;
        }else{
            return null;
        }
    }

    @Override
    public void del(Long orderid){
        jdbcTemplate.update("delete from records where orderid=?", orderid);
    }
}
